package com.newjiabo.web.controller.ski;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.newjiabo.common.annotation.RepeatSubmit;
import com.newjiabo.ski.domain.SkiOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.newjiabo.common.annotation.Log;
import com.newjiabo.common.core.controller.BaseController;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.common.enums.BusinessType;
import com.newjiabo.ski.service.ISkiOrderService;
import com.newjiabo.common.utils.poi.ExcelUtil;
import com.newjiabo.common.core.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author CaoMengHui
 * @date 2023-09-22
 */
@Api(tags = "后台-订单管理")
@RestController
@RequestMapping("/system/order")
public class SkiOrderController extends BaseController {
    @Autowired
    private ISkiOrderService skiOrderService;

    /**
     * 查询订单列表
     */
    @ApiOperation(value = "查询订单列表")
    @PreAuthorize("@ss.hasPermi('ski:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkiOrder skiOrder) {
        startPage();
        List<SkiOrder> list = skiOrderService.selectSkiOrderList(skiOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @ApiOperation(value = "导出订单列表")
    @PreAuthorize("@ss.hasPermi('ski:order:export')")
    @Log(title = "导出订单列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkiOrder skiOrder) {
        List<SkiOrder> list = skiOrderService.selectSkiOrderList(skiOrder);
        ExcelUtil<SkiOrder> util = new ExcelUtil<SkiOrder>(SkiOrder.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @ApiOperation(value = "获取订单详细信息")
    @PreAuthorize("@ss.hasPermi('ski:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        return AjaxResult.success(skiOrderService.getInfoDetail(orderId));
    }

    /**
     * 修改订单
     */
    @RepeatSubmit
    @ApiOperation(value = "修改订单")
    @PreAuthorize("@ss.hasPermi('ski:order:edit')")
    @Log(title = "修改订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkiOrder skiOrder) {
        return toAjax(skiOrderService.updateSkiOrder(skiOrder));
    }

    /**
     * 删除订单
     */
    @ApiOperation(value = "删除订单")
    @PreAuthorize("@ss.hasPermi('ski:order:remove')")
    @Log(title = "删除订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds) {
        return toAjax(skiOrderService.deleteSkiOrderByOrderIds(orderIds));
    }
}
